package com.daidai.activitys

import android.app.ActivityManager
import android.graphics.BitmapFactory
import android.os.Debug
import com.daidai.base.BaseActivity
import com.daidai.spinner.R
import com.daidai.tools.G

class BitmapActivity : BaseActivity() {

    override fun getContentViewResId(): Int  = R.layout.activity_bitmap

    override fun initView() {
        findBtn(R.id.btnShowMem).setOnClickListener {
            showMem()
        }
        findBtn(R.id.btnLoad).setOnClickListener {
            val bitmap = BitmapFactory.decodeResource(resources,R.drawable.no_bg)
            G.elog("bitmap size, width:${bitmap.width},height:${bitmap.height}")
            showMem()
        }
    }

    override fun initData() {
    }

    fun showMem(){
        val am = getSystemService(ACTIVITY_SERVICE) as ActivityManager
        val memInfo = ActivityManager.MemoryInfo()
        am.getMemoryInfo(memInfo)

        G.elog("===================================================")
        G.elog("可用内存:${memInfo.availMem/1024/1024} M")
        G.elog("is low memory: ${memInfo.lowMemory}")
        G.elog("getNativeHeapAllocatedSize mem:${Debug.getNativeHeapAllocatedSize()/1024/1024} M")
        G.elog("getNativeHeapFreeSize mem:${Debug.getNativeHeapFreeSize()/1024/1024} M")
        G.elog("getNativeHeapSize mem:${Debug.getNativeHeapSize()/1024/1024} M")
    }
}